package com.sdleyou.treepro.business.api.rank;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.UserRankManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/api")
public class RankController {
    @Autowired
    private UserRankManager userRankManager;

    @ApiVersion(1)
    @GetMapping("/{version}/rank/users")
    public ResultVO userRank(@RequestParam(name = "page_size", defaultValue = "5") Integer pageSize,
                             @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum,
                             @RequestParam("user_id") @NotEmpty(message = "user_id不能为空") String userId) {
        return ResultVOUtil.success(userRankManager.userRank(pageSize, pageNum, userId));
    }

    @ApiVersion(1)
    @GetMapping("/{version}/rank/companies")
    public ResultVO companyRank(@RequestParam(name = "page_size", defaultValue = "5") Integer pageSize,
                                @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum,
                                @RequestParam("company_id") @NotEmpty(message = "company_id不能为空") String companyId) {
        return ResultVOUtil.success(userRankManager.companyRank(pageSize, pageNum, companyId));
    }
}
